package weaver.interfaces.cese.duss.action.srm;

import com.engine.cese.duss.srm.util.GenUtil;
import com.weaver.general.BaseBean;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-10-23
 * @Description: 流程流程
 * @ModifyLog:
 **/
/*
 *@Description: 参数采购立项单触发流标流程，审批后改流标
 *@Param:
 *@return:
 *@Author: Dusongsong
 *@Date: 2020/12/10
 */
public class WeaFlowLableAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        String requestid = requestInfo.getRequestid();
        //主表
        String tablename = requestInfo.getRequestManager().getBillTableName();
        try {
            String sql  ="select cglxd from "+tablename+" where requestid=?";
            rs.executeQuery( sql,requestid );
            rs.next();
            //招标采购立项
            String cglxd = Util.null2String( rs.getString( "cglxd" ));
            BaseBean baseBean = new BaseBean();
            String zbcglx = baseBean.getPropValue( "SrmWfTab", "zbcglx" );
            String sql1 = "select t.cglx,wm_concat(t1.rwdid) as rwdids from " + zbcglx + " t left join " +
                    zbcglx + "_dt2 t1 on t.id=t1.mainid where t.requestid=? group by t.cglx";
            rs.executeQuery( sql1, cglxd );
            rs.next();
            String cglx = Util.null2String( rs.getString( "cglx" ) );
            String rwdids = Util.null2String( rs.getString( "rwdids" ) );
            String cgrwTable = GenUtil.getCgrwTableType( cglx );
            String sql2 = "update " + cgrwTable + " set rwzt=0 where id in (" + rwdids + ")";
            rs.executeUpdate( sql2 );
            String sql3 = "update " + zbcglx + " set xmzt=2 where requestid=?";
            rs.executeUpdate( sql3, cglxd );
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            writeLog( "异常参考:" + e );
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "Action接口异常！" );
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}
